package com.sleepapp.controller.module;


import com.sleepapp.annotation.SaAdminCheckLogin;
import com.sleepapp.annotation.SaUserCheckLogin;
import com.sleepapp.service.CheckInRecordService;
import com.sleepapp.utils.AjaxResult;
import com.sleepapp.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 打卡记录表 前端控制器
 * </p>
 *
 * @author 
 * @since 2025-03-13
 */
@RestController
@RequestMapping("/checkInRecord")
public class CheckInRecordController {

    @Autowired
    private CheckInRecordService checkInRecordService;

    /**
     * 获取用户仪表盘数据
     * @folder 仪表盘
     */
    @GetMapping("/dashboard")
    @SaUserCheckLogin
    public AjaxResult<DashboardData> dashboard() {
        return AjaxResult.success(checkInRecordService.dashboard());
    }

    @GetMapping("/getAll")
    @SaAdminCheckLogin
    public AjaxResult<PageQueryInfo<List<CheckInRecordQueryAllVo>>> getAll(@ModelAttribute @Valid PageQueryParamVo pageQueryParamVo) {
        return AjaxResult.success(checkInRecordService.getAll(pageQueryParamVo));
    }

    @PostMapping("/save")
    @SaAdminCheckLogin
    public AjaxResult<Void> save(@RequestBody @Valid CheckInRecordAddVo checkInRecordAddVo) {
        checkInRecordService.save(checkInRecordAddVo);
        return AjaxResult.success();
    }

    @DeleteMapping("/delete/{id}")
    @SaAdminCheckLogin
    public AjaxResult<Void> delete(@PathVariable Long id) {
        if (checkInRecordService.delete(id)) {
            return AjaxResult.success();
        }

        return AjaxResult.fail();
    }

}

